﻿using System;

namespace Ymatou.Evaluate.Common
{
    public static class Util
    {
        /// <summary>
        /// 数字转换
        /// </summary>
        /// <param name="value">值</param>
        /// <param name="flag">true:乘100；false:除100</param>
        /// <param name="format">格式化</param>
        /// <returns></returns>
        public static decimal DecimalConvert(decimal value, bool flag, string format = "0.0")
        {
            if (flag)
                return Convert.ToDecimal(value.ToString(format)) * 100;
            else
                return Convert.ToDecimal((value / 100).ToString(format));
        }

        public static long DateTime2LongTime(this DateTime postTime)
        {
            var tsp = (postTime - new DateTime(1970, 1, 1).ToLocalTime());
            return Convert.ToInt64(tsp.TotalMilliseconds);
        }

        public static DateTime LongTime2DateTime(this long longPostTime)
        {
            if (longPostTime == 0) return DateTime.Now;
            return new DateTime(1970, 1, 1).ToLocalTime().AddMilliseconds(longPostTime);
        }
    }
}
